package com.distributed.tcp.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * TCP配置
 */
@Data
@ConfigurationProperties(prefix = "tcp.server")
public class TcpServerProperties {
    private List<Integer> initialPorts;
    private long configRefreshInterval;
    private int lockTimeout;
    private int connectionTimeout;
    private Map<Integer, ThreadPoolConfig> threadPools = new HashMap<>();
    private Map<Integer, String> messageHandlerMapping = new HashMap<>();
    private ForwardConfig forward = new ForwardConfig();

    @Data
    public static class ThreadPoolConfig {
        private int coreSize = Runtime.getRuntime().availableProcessors(); // 默认CPU核心数
        private int maxSize = Runtime.getRuntime().availableProcessors() * 2; // 默认CPU核心数*2
        private int keepAliveSeconds = 60; // 默认60秒
        private int queueCapacity = 1024; // 默认队列容量
    }

    @Data
    public static class ForwardConfig {
        private int maxRetry = 3; // 最大重试次数
        private int retryInterval = 1000; // 重试间隔(ms)
        private String directUrlPrefix = "http://%s:%d/api/remote/forward"; // 直接转发URL模板
    }
}
